	package trunk.trunk.besteAukera;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ScrollPane;
import java.util.LinkedList;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.Box;

import besteAukera.Chip;
import besteAukera.UAL;


public class Nagusia {
	  private static LienzoParaArrastrarFigurasChip c ;
	/**
	 * @param args

	     */
	    public static void main(String[] args)
	    {
	        JFrame v = new JFrame("Arrastrar Grafico");
	        v.setBackground(Color.black);
	        ScrollPane proba = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
	    c = new LienzoParaArrastrarFigurasChip();
	    proba.add(c);
		    v.getContentPane().setLayout(new BorderLayout());
		    JButton andAnd=new JButton();
		    andAnd.setText("And And ");
		    JButton andOr=new JButton();
		    andOr.setText("And   Or  ");
		    JButton andNand=new JButton();
		    andNand.setText("AndNand");
		    JButton andNor=new JButton();
		    andNor.setText("And  Nor ");
		    JButton equAnd=new JButton();
		    equAnd.setText("EquAnd");
		    JButton equOr=new JButton();
		    equOr.setText("EquOr");
		    JButton equNor=new JButton();
		    equNor.setText("EquNor");
		    JButton equNand=new JButton();
		    equNand.setText("EquNand");
		    JButton xorAnd=new JButton();
		    xorAnd.setText("XorAnd");
		    JButton xorOr=new JButton();
		    xorOr.setText("XorOr");
		    JButton xorNand=new JButton();
		    xorNand.setText("XorNand");
		    JButton xorNor=new JButton();
		    xorNor.setText("XorNor");
		    JButton orOr=new JButton();
		    orOr.setText("Or   Or");
		    JButton orAnd=new JButton();
		    orAnd.setText("Or  And");
		    JButton orNor=new JButton();
		    orNor.setText("Or  Nor");
		    JButton orNand=new JButton();
		    orNand.setText("OrNand");
		    JButton kablea=new JButton();
		    kablea.setText("Kablea");
		    JButton notPosNeg=new JButton();
		    notPosNeg.setText("Not");
		    JButton notNegPos=new JButton();
		    notNegPos.setText("Not");
		    JButton dekodegailua=new JButton();
		    dekodegailua.setText("Dekodegailua");
		    JButton multilau=new JButton();
		    multilau.setText("2ko Multiplexorea");
		    JButton multizortzi=new JButton();
		    multizortzi.setText("4ko Multiplexorea");
		    JButton notFisikoaPosNeg=new JButton();
		    notFisikoaPosNeg.setText("Not Fisikoa /PosNeg");
		    JButton notFisikoaNegPos=new JButton();
		    notFisikoaNegPos.setText("Not Fisikoa /NegPos");
		    JButton exekutatu=new JButton();
		    exekutatu.setText("Exekutatu");
		    JButton konparagailua=new JButton();
		    konparagailua.setText("Konparagailua");
		    JButton batugailu=new JButton();
		    batugailu.setText("Batugailua");
		    JButton kengailu=new JButton();
		    kengailu.setText("Kengailua");
		    JButton batken=new JButton();
		    batken.setText("Batugailu/Kengailu");
		    JButton JK=new JButton();
		    JK.setText("JK Biegonkorra");
		    JButton D =new JButton();
		    D.setText("D Biegonkorra");
		    JButton sr =new JButton();
		    sr.setText("SR Biegonkorra");
		    JButton erre =new JButton();
		    erre.setText("Erregistroa");
		    JButton ual =new JButton();
		    ual.setText("UAL");
		    //ez du ondo funzionatzen, bakarrik mota berdineko chip batekin funtzionatzen du
		    //zure ordenadorean dago gordeta (favoritosen) web orri bat honi buruzko azalpen batzukin
		    //(edo hori ustet behitzat). GAINERA FOR BATEKIN EGIN BEHARKO DA, AUTOMATIKOKI CHIPAK 
		    //BEKTORETIK HARTZEKO
		    konparagailua.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new Konparagailua(c.getX(), c.getY(),5,2, "and");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    ual.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new UAL(c.getX(), c.getY(),10,5, null);
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    sr.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new SRBiegonkorra(c.getX(), c.getY(),6,4);
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    erre.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new Erregistroak(c.getX(), c.getY(),4,3,"and");
				    c.addFigura(n);
				c.repaint();
			
				}
			});

		    JK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new JKBiegonkorra(c.getX(), c.getY(),6,4, "and");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    D.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new DBiegonkorra(c.getX(), c.getY(),5,3, "and");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    batugailu.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new BatugailuKengailu(c.getX(), c.getY(),5,3, "bat");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    kengailu.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new BatugailuKengailu(c.getX(), c.getY(),5,3,  "ken");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    batken.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new BatugailuKengailu(c.getX(), c.getY(),5,3,  "batken");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    andAnd.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new And(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"and");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    andOr.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new And(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"or");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    andNand.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new And(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nand");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    andNor.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new And(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nor");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    dekodegailua.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new Dekodegailu(c.getX(), c.getY(),7,2, 70, "and");
				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    kablea.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
			
			        final Chip n=new Kablea(90, 90, 2,1, 70, 50, 270, 180,"and");				    c.addFigura(n);
				c.repaint();
			
				}
			});
		    exekutatu.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					

				//	******************************************
					Vector<Chip> chipLista=c.getChipLista();
					for (Chip txip : chipLista)
						txip.hasieratu();
					
					for (Chip txip : chipLista){
						
				    	new Thread(txip).start();
						
					}
					
					c.repaint();
				}
			});
		    equAnd.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Equ(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"and");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    equOr.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Equ(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"or");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    equNand.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Equ(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nand");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    equNor.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Equ(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nor");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    orAnd.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Or(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"and");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    orOr.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Or(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"or");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    orNand.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Or(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nand");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    orNor.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Or(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nor");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    xorAnd.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Xor(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"and");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    xorOr.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Xor(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"or");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    xorNand.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Xor(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nand");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    xorNor.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					final Chip n=new Xor(c.getX(), c.getY(),3,2, 70, 50, 270, 180,"nor");
				    c.addFigura(n);
					c.repaint();
				}
			});
		    notPosNeg.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Not(c.getX(), c.getY(),2,1, 70, 50, 270, 180,"posNeg");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    notNegPos.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Not(c.getX(), c.getY(),2,1, 70, 50, 270, 180,"negPos");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    notFisikoaPosNeg.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new NotFisikoa(c.getX(), c.getY(),2,1, 70, 50, 270, 180,"posNeg");
				    c.addFigura(n);
				c.repaint();	
				}
			});
		    notFisikoaNegPos.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new NotFisikoa(c.getX(), c.getY(),2,1, 70, 50, 270, 180,"negPos");
				    c.addFigura(n);
				    c.repaint();
				}
			});
		    multilau.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Multiplexorea(c.getX(), c.getY(),5,4,  "lau");
				    c.addFigura(n);
				    c.repaint();
				}
			});
		    multizortzi.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    final Chip n=new Multiplexorea(c.getX(), c.getY(),8,7,  "zortzi");
				    c.addFigura(n);
				    c.repaint();
				}
			});
		    Box botoiak=Box.createHorizontalBox();
		    Box and=Box.createVerticalBox();
		    Box biegonkorrak=Box.createVerticalBox();
		    Box or=Box.createVerticalBox();
		    Box equ=Box.createVerticalBox();
		    Box xor=Box.createVerticalBox();
		    Box not=Box.createVerticalBox();
		    Box notFis=Box.createVerticalBox();
		    and.add(andAnd);
		    and.add(andOr);
		    and.add(andNand);
		    and.add(andNor);
		    or.add(orOr);
		    or.add(orAnd);
		    or.add(orNor);
		    or.add(orNand);
		    xor.add(xorOr);
		    xor.add(xorAnd);
		    xor.add(xorNor);
		    xor.add(xorNand);
		    equ.add(equOr);
		    equ.add(equAnd);
		    equ.add(equNor);
		    equ.add(equNand);
		    not.add(notNegPos);
		    not.add(notPosNeg);
		    notFis.add(notFisikoaNegPos);
		    notFis.add(notFisikoaPosNeg);
		    botoiak.add(and);
		    botoiak.add(equ);
		    botoiak.add(xor);
		    botoiak.add(or);
		    botoiak.add(multilau);
		    botoiak.add(multizortzi);
		    botoiak.add(not);
		    botoiak.add(kablea);
		    botoiak.add(dekodegailua);
		    botoiak.add(notFis);
		    botoiak.add(konparagailua);
		    botoiak.add(batugailu);
//		    botoiak.add(kengailu);
//		    botoiak.add(batken);
		    biegonkorrak.add(JK);
		    biegonkorrak.add(D);
		    biegonkorrak.add(sr);
		    biegonkorrak.add(erre);
		    biegonkorrak.add(ual);
		    v.getContentPane().add(botoiak,BorderLayout.NORTH);
		    v.getContentPane().add(biegonkorrak,BorderLayout.WEST);
		    v.getContentPane().add(exekutatu,BorderLayout.EAST);
		    v.getContentPane().add(proba, BorderLayout.CENTER);
		     v.pack();
	        v.setVisible(true);
	        v.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	        
	    }
	
	    
	
}
